<template>
  <a-row>
    <a-col span="4">
      <div style="overflow-y: scroll; height: 900px;">
        <a-card :bordered="true" :bodyStyle="{padding:'0'}">
          <a-row style="height: 900px;">
            <a-row style="margin-top: 10px">
              <a-col span="24">
                <a-input-search placeholder="搜索门诊单" style="width:74%;margin-left: 3px" enter-button/>
                <a-button type="primary"  style="width:20%;margin-left: 3px" >
                  接诊
                </a-button>
              </a-col>
            </a-row>
            <a-tabs default-active-key="1" style="width:96%;margin-left: 2px" >
              <a-tab-pane key="0" tab="全部">
              </a-tab-pane>
              <a-tab-pane key="1" tab="待诊">
              </a-tab-pane>
              <a-tab-pane key="2" tab="已诊" force-render>
              </a-tab-pane>
            </a-tabs>
            <a-row style="margin-left: 4px;margin-right: 4px">
              <a-range-picker format="YYYY-MM-DD"
               :default-value="[moment(getCurrentDate()), moment(getCurrentDate(3))]" @change="onChangeByDate" >
              </a-range-picker>
            </a-row>

            <a-list item-layout="horizontal" :data-source="patientData" style="margin-top: 10px">
              <div
                v-if="showLoadingMore"
                slot="loadMore"
                :style="{ textAlign: 'center', marginTop: '12px',marginBottom:'12px', height: '32px', lineHeight: '32px' }"
              >
                <a-spin v-if="loadingMore" />
                <a-button @click="onLoadMore" style="margin-bottom: 12px">
                  加载更多
                </a-button>
              </div>
              <a-list-item slot="renderItem" slot-scope="item, index" >
                <a-card :bodyStyle="chooseId==item.id?bodyStyle1:bodyStyle0" :bordered="false" style="width:96%" @click="handleChoosePatient(item)">
                  <a-row style="margin: 10px 10px 5px 20px">
                    <a-col span="8">
                      <label :style="chooseId==item.id?'font-weight: bold;color:white':'font-weight: bold;'">{{ item.patientName }}</label>
                    </a-col>
                    <a-col span="8" align="center">
                      <span :style="chooseId==item.id?'font-weight: bold;color:white':'font-weight: bold;color:#959393'">{{ item.patientAge }}岁</span>
                    </a-col>
                    <a-col span="8" align="right">
                      <label :style="chooseId==item.id?'margin-left: 14px;margin-right: 2px;color:white':'margin-left: 10px;margin-right: 2px;color:#4da0ff'">待诊</label>
                    </a-col>
                  </a-row>
                  <a-row style="margin: 0px 10px 20px 20px">
                    <a-col span="12">
                      <label :style="chooseId==item.id?'font-weight: bold;color:white':'font-weight: bold;color:#959393'">{{ item.patientPhone }}</label>
                    </a-col>
                    <a-col span="12" align="right">
                      <label :style="chooseId==item.id?'font-weight: bold;color:white':'font-weight: bold;color:#959393'">{{item.subsectionName}}{{item.sort}}</label>
                    </a-col>
                  </a-row>
                </a-card>
              </a-list-item>
            </a-list>
          </a-row>

        </a-card>
      </div>

      <!--        <a-row>-->
      <!--          <a-list item-layout="horizontal" style="margin-left: 12px;margin-right: 12px">-->
      <!--            <a-list-item>-->
      <!--              <a-col @click="handleOpenWork">-->
      <!--                <img src="../../assets/data1.png" />-->
      <!--                <label style="margin-left: 8px;font-weight: bold;color:#959393;font-size: medium">门诊看板</label>-->
      <!--              </a-col>-->
      <!--              <a-col>-->
      <!--                <label style="font-weight: bold;color:#959393">医生工作汇总</label>-->
      <!--              </a-col>-->
      <!--            </a-list-item>-->

      <!--            <a-list-item>-->
      <!--              <a-col @click="handleOpenReservation">-->
      <!--                <img src="../../assets/data2.png" />-->
      <!--                <label style="margin-left: 8px;font-weight: bold;color:#959393;font-size: medium">预约看板</label>-->
      <!--              </a-col>-->
      <!--              <a-col>-->
      <!--                <label style="font-weight: bold;color:#959393">挂号预约情况</label>-->
      <!--              </a-col>-->
      <!--            </a-list-item>-->

      <!--            &lt;!&ndash;            <a-list-item>&ndash;&gt;-->
      <!--            &lt;!&ndash;              <a-col>&ndash;&gt;-->
      <!--            &lt;!&ndash;                <img src="../../assets/data3.png" />&ndash;&gt;-->
      <!--            &lt;!&ndash;                <label style="margin-left: 8px;font-weight: bold;color:#959393;font-size: medium">用药助手</label>&ndash;&gt;-->
      <!--            &lt;!&ndash;              </a-col>&ndash;&gt;-->
      <!--            &lt;!&ndash;              <a-col>&ndash;&gt;-->
      <!--            &lt;!&ndash;                <label style="font-weight: bold;color:#959393">安全合理用药</label>&ndash;&gt;-->
      <!--            &lt;!&ndash;              </a-col>&ndash;&gt;-->
      <!--            &lt;!&ndash;            </a-list-item>&ndash;&gt;-->
      <!--          </a-list>-->
      <!--        </a-row>-->
    </a-col>
    <a-col span="15">
      <div style="overflow-y: scroll; height: 900px;">
        <div>
          <a-card :bordered="false" :bodyStyle="{padding:'0'}">
            <a-button slot="extra" @click="handleOpenCostBrowsing()">费用预览</a-button>
            <a-button slot="extra" style="margin-left: 10px" type="primary" @click="handleSubmit(0)">提交预诊</a-button>
            <a-button slot="extra" style="margin-left: 10px" type="primary" @click="handleSubmit(1)">完成接诊</a-button>
            <a-popconfirm title="是否确认删除?" ok-text="是" cancel-text="否" slot="extra">
              <a-button>删除</a-button>
            </a-popconfirm>
          </a-card>
          <a-card :bodyStyle="{padding:'1'}">
            <a-row style="height: 40px;">
              <a-col>
                <a-input
                  v-model="model.patientName"
                  show-search
                  style="width: 200px"
                  placeholder="输入姓名查询" :allowClear="true" />
                <a-select default-value="男" style="width: 70px;margin-left: 16px" v-model="model.patientSex">
                  <a-select-option value="男">
                    男
                  </a-select-option>
                  <a-select-option value="女">
                    女
                  </a-select-option>
                </a-select>

                <a-input
                  v-model="model.patientName"
                  show-search
                  style="width: 100px;margin-left: 16px"
                  placeholder="" /> <span style='margin-left: 16px'>岁</span>

                <a-input
                  v-model="model.patientName"
                  show-search
                  style="width: 100px;margin-left: 20px"
                  placeholder="" /><span style='margin-left: 8px'>月</span>

                <a-input
                  v-model="model.patientName"
                  show-search
                  style="width: 120px;margin-left: 16px"
                  placeholder="手机号" />

                <!--                <a-select default-value="初诊" style="width: 80px">-->
                <!--                  <a-select-option value="初诊">-->
                <!--                    初诊-->
                <!--                  </a-select-option>-->
                <!--                </a-select>-->
                <!--                <a-select default-value="自费" style="width: 80px">-->
                <!--                  <a-select-option value="自费">-->
                <!--                    自费-->
                <!--                  </a-select-option>-->
                <!--                </a-select>-->
              </a-col>
            </a-row>
          </a-card>
          <a-card title="病历" style="margin-top: 10px">
            <a-button slot="extra" style="margin-left: 10px" @click="handleSetUp">病历设置</a-button>
            <a-form-model ref="form">
              <a-form-model-item label="发病日期" :labelCol="{span: 2}" :wrapperCol="{span: 20}">
                <a-date-picker style="width: 100px;margin-left: 10px"
                               v-model="model.caseDate"
                               show-time
                               type="date"
                               format="YYYY-MM-DD"
                               :defaultValue="moment(getCurrentData(), 'YYYY-MM-DD')"></a-date-picker>
              </a-form-model-item>

              <a-form-model-item label="主诉" :labelCol="{span: 2}" :wrapperCol="{span: 20}">
                <a-popover title="" placement="bottom" trigger="click">
                  <template slot="content">
                    <a-row v-for="date in caseMainData" style="width: 700px">
                      <a-tag v-for="tag in date.itemList" @click="handleChange(tag.name,'主诉')"
                             style="margin-top: 8px;margin-left: 8px"
                             color="#ffffff">
                        <label style="color: #bfbfbf;font-size: 15px"> {{ tag.name }}</label>
                      </a-tag>
                      <a-divider />
                    </a-row>
                  </template>
                  <a-input
                    v-model="model.caseTitle"
                    @mousedown="onSearchCareMain()"
                    style="width: 95%"
                    @focus="fetchCareMain"
                  />
<!--                  <div class="transition-input-box-panel__body">-->
<!--                    <a-card>-->
<!--                      <a-row v-for="date in caseMainData" style="width: 800px">-->
<!--                        <a-tag v-for="tag in date.itemList" @click="handleChange(tag.name,'主诉')"-->
<!--                               style="margin-top: 8px;margin-left: 8px"-->
<!--                               color="#ffffff">-->
<!--                          <label style="color: #bfbfbf;font-size: 15px"> {{ tag.name }}</label>-->
<!--                        </a-tag>-->
<!--                        <a-divider />-->
<!--                      </a-row>-->
<!--                    </a-card>-->
<!--                  </div>-->
                </a-popover>

              </a-form-model-item>
              <!--              <a-form-model-item label="现病史" :labelCol="{span: 2}" :wrapperCol="{span: 20}">-->
              <!--                <a-input placeholder="" v-model="model.tableNo" />-->
              <!--              </a-form-model-item>-->
              <a-form-model-item label="既往史" :labelCol="{span: 2}" :wrapperCol="{span: 20}"
                                 v-if="careFormatModel.careHistory.checked">
                <a-popover title="" placement="bottom" trigger="click">
                  <template slot="content">
                    <a-row v-for="data in casePastHistoryData" style="width: 700px;margin-top: 10px">
                      <h4 v-if="data.izShow=='1'">{{ data.category }}</h4>
                      <a-tag v-for="tag in data.itemList" @click="handleChange(tag.name,'既往史')"
                             style="margin-top: 4px;margin-left: 8px"
                             color="#ffffff">
                        <label style="color: #bfbfbf;font-size: 15px"> {{ tag.name }}</label>
                      </a-tag>
                    </a-row>
                  </template>
                  <a-input
                    v-model="model.historyResult"
                    style="width: 95%"
                    @change="fetchCarePastHistory"
                  />
                </a-popover>

              </a-form-model-item>
              <a-form-model-item label="过敏史" :labelCol="{span: 2}" :wrapperCol="{span: 20}"
                                 v-if="careFormatModel.careAllergy.checked">
                <a-popover title="" placement="bottom" trigger="click">
                  <template slot="content">
                    <a-row v-for="date in caseAllergyHistoryData" style="width: 500px">
                      <a-tag v-for="tag in date.itemList" @click="handleChange(tag.name,'过敏史')"
                             style="margin-top: 8px;margin-left: 8px"
                             color="#ffffff">
                        <label style="color: #bfbfbf;font-size: 15px"> {{ tag.name }}</label>
                      </a-tag>
                      <a-divider />
                    </a-row>
                  </template>
                  <a-input
                    v-model="model.allergyResult"
                    style="width: 95%"
                    @change="fetchCareAllergyHistory"
                  />
                </a-popover>

              </a-form-model-item>
              <a-form-model-item label="体格检查" :labelCol="{span: 2}" :wrapperCol="{span: 20}"
                                 v-if="careFormatModel.careCheckUp.checked">
                <a-popover title="" placement="bottom" trigger="click">
                  <template slot="content">
                    <a-row>
                      <h4>{{ caseCheckUpData.category }}</h4>
                      <a-tag v-for="tag in caseCheckUpData.itemList" @click="handleChange(tag.name,'体格检查')"
                             style="margin-top: 8px;margin-left: 8px"
                             color="#ffffff">
                        <label style="color: #bfbfbf;font-size: 15px"> {{ tag.name }}</label>
                      </a-tag>
                    </a-row>
                    <a-row style="width: 800px">
                      <a-tabs>
                        <a-tab-pane :key="date.key" :tab="date.category" v-for="date in caseCheckUpData.categoryList">
                          <a-tag v-for="tag in date.itemList" @click="handleChange(tag.name,'体格检查')"
                                 style="margin-top: 8px;margin-left: 8px" color="#ffffff">
                            <label style="color: #bfbfbf;font-size: 15px"> {{ tag.name }}</label>
                          </a-tag>
                        </a-tab-pane>
                      </a-tabs>
                    </a-row>
                  </template>
                  <a-input
                    v-model="model.checkUp"
                    @focus="onSearchCareMain()"
                    style="width: 95%"
                    @change="fetchCareCheckUpData"
                  />
                </a-popover>
              </a-form-model-item>

              <a-form-model-item label="望闻切诊" :labelCol="{span: 2}" :wrapperCol="{span: 20}"
                                 v-if="careFormatModel.careLook.checked">
                <a-input placeholder="" v-model="model.inspection" />
              </a-form-model-item>
              <a-form-model-item label="诊断" :labelCol="{span: 2}" :wrapperCol="{span: 20}">
                <a-popover title="" placement="bottom" trigger="click">
                  <template slot="content">
                    <a-row style="width: 700px">
                      <h4 style="color: #bfbfbf;font-size: 15px" v-for="date in caseDiagnosisData"
                          @click="handleChange(date.name,'诊断')"> {{ date.name }}</h4>
                    </a-row>
                  </template>
                  <a-input
                    v-model="model.caseResult"
                    style="width: 95%"
                    @change="fetchCareDiagnosis"
                  />
                </a-popover>
              </a-form-model-item>
              <a-form-model-item label="辨证" :labelCol="{span: 4}" :wrapperCol="{span: 20}" style="margin-left: 30px"
                                 v-if="careFormatModel.careDialectic.checked">

                <a-popover title="" placement="bottom" trigger="click">
                  <template slot="content">
                    <a-row style="width: 420px">
                      <h4 style="color: #bfbfbf;font-size: 15px" v-for="date in caseDialecticData"
                          @click="handleChange(date.name,'辨证')"> {{ date.name }}</h4>
                    </a-row>
                  </template>
                  <a-input
                    v-model="model.dialectic"
                    style="width: 95%"
                    @change="fetchCaseDialecticData"
                  />
                </a-popover>
              </a-form-model-item>

            </a-form-model>
          </a-card>


          <a-card title="诊疗项目" style="margin-top: 20px">
            <a-button slot="extra" style="margin-left: 10px">检查</a-button>
            <a-button slot="extra" style="margin-left: 10px" @click="handleOpenProject('治疗理疗')">治疗理疗</a-button>
            <a-button slot="extra" style="margin-left: 10px">耗材</a-button>

            <a-row v-for="(item,index) in projectDataSource" style="margin-bottom: 15px">
              <a-row v-if="item.categoryCode=='1'">
                <a-col span="10" >{{ item.projectName }}</a-col>
                <a-col span="14" align="right">
                  <span style="color: #a1a4ad">{{item.categoryName}}</span>
                  <a-input-number v-model="item.qty" :min="0" placeholder="每天" style="margin-left: 16px;width:70px"  @change="onCallProjectCal" @focus="onFocusProjectCal(index)"/>
                  {{ item.unit }}
                  <a-input-number v-model="item.day" :min="0" style="width:70px" @change="onCallProjectCal" @focus="onFocusProjectCal(index)"/>
                  天,
                  <span style="margin-left: 10px;">共</span>
                  <a-input-number v-model="item.totalQty" :min="0"  style="margin-left: 8px;width:70px"/>
                  {{ item.unit }}
                </a-col>
              </a-row>
              <a-row v-if="item.categoryCode=='2'||item.categoryCode=='3'">
                <a-col span="10" >{{ item.projectName }}</a-col>
                <a-col span="14" align="right">
                  <span style="color: #a1a4ad">治疗理疗</span>
                  <span style="margin-left: 16px;">共</span>
                  <a-input-number v-model="item.totalQty" style="margin-left: 8px;width:70px"/>
                  {{ item.unit }}
                </a-col>
              </a-row>
            </a-row>

            <a-row style="margin-top: 10px">
              <!--搜索框-->
              <a-popover title="" placement="bottom" trigger="click">
                <template slot="content">
                  <a-table
                    ref="table"
                    size="middle"
                    bordered
                    :scroll="{ x: 500,y: 200}"
                    rowKey="id"
                    :pagination="false"
                    :columns="columnsMedicine"
                    :dataSource="medicineData"
                    :customRow="onSearchRowByMedicine"
                    style="margin-top: 10px" />
                </template>
                <a-auto-complete
                  v-model="medicineValue"
                  :data-source="dataSource"
                  style="width: 95%"
                  placeholder="输入项目名称"
                >
                  <a-input>
                    <a-icon slot="prefix" type="search" class="certain-category-icon" />
                  </a-input>
                </a-auto-complete>
              </a-popover>
            </a-row>
          </a-card>

          <a-card title="处方医嘱" style="margin-top: 20px">
            <a-button slot="extra" @click="showTable('西药处方')">西药处方</a-button>
            <a-button slot="extra" style="margin-left: 10px" @click="showTable('中药处方')">中药处方</a-button>
            <a-button slot="extra" style="margin-left: 10px" @click="showTable('输注处方')">输注处方</a-button>
<!--            <a-button slot="extra" style="margin-left: 10px">外注处方</a-button>-->
            <a-button slot="extra" style="margin-left: 10px">处方模板</a-button>

          </a-card>

          <!--西药处方-->
          <a-card v-if="isMedicine" :headStyle="{color:'#8a8a8a'}">
            <template #title>
              <img src="../../assets/table_icon1.png" /> 西药处方
            </template>
            <span slot="extra" style="font-weight: bold;"> 合计：￥{{ medicineAmount }}</span>
            <a-icon slot="extra" type="save" @click="delMedicine" style="margin-left: 60px" />
            <a-icon slot="extra" type="delete" @click="delMedicine" style="margin-left: 10px" />
            <table>
              <thead>
              <tr>
                <th>药名</th>
                <th  align="center">用法</th>
                <th  align="center">频次</th>
                <th  align="center">每次用量</th>
                <th  align="center">天数</th>
                <th  align="center">总用量</th>
                <th  align="center">备注</th>
              </tr>
              </thead>
              <tbody>
              <tr v-if="isMedicine&&medicineDataSource.length>0" v-for="(record,index) in medicineDataSource">
                <td>
                  <a-input :value="record.medicineName+'  '+record.standard" style="width: 96%" disabled="disabled" />
                </td>
                <td style="width: 11%">
                  <!---使用方法-->
                  <j-dict-select-tag style="width: 95%;"
                                     placeholder="请选择给药途径"
                                     dictCode="drug_delivery_route"
                                     v-model="record.usages" />
                </td>
                <td style="width: 11%">
                  <!---频次-->
                  <j-dict-select-tag
                    style="width: 95%;margin-left: 4px"
                    placeholder="请选择频次"
                    dictCode="use_frequency"
                    v-model="record.frequency" />
                </td>
                <td style="width: 15%">
                  <!---每次用量-->
                  <a-input-number v-model="record.dose" placeholder="每次用量" :min="0"  style="width: 45%;margin-left: 4px" @change="onCallWesternCalByMinUnit" />
                  <a-select v-model='record.conversionUnit'  style="width: 45%;margin-left: 2px" @change="onCallWesternCalByMinUnit">
                    <a-select-option v-for='item in record.conversionUnitList' :key='item' :value='item'>{{ item }} </a-select-option>
                  </a-select>
                </td>
                <td style="width: 9%">
                  <!---服用天数-->
                  <a-input-number v-model="record.day"   style="width: 95%" placeholder="服用天数"  :min="0"  @change="onCallWesternCalByMinUnit"/>
                </td>
                <td style="width: 14%">
                  <a-input-number  v-model="record.totalDose" style="width: 45%" placeholder="总用量"  :min="0" @change="onCallWesternCalByMaxUnit"/>
                  <a-select v-model='record.unit'  style="width: 45%;margin-left: 2px" @change="onCallWesternCalByMinUnit">
                    <a-select-option v-for='item in record.unitList' :key='item' :value='item'>{{ item }} </a-select-option>
                  </a-select>
                </td>
                <td style="width: 11%">
                  <!---备注-->
                  <a-input v-model="record.remark" placeholder="备注" />
                </td>
              </tr>
              </tbody>
            </table>

            <a-row style="margin-top: 20px">
              <!--搜索框-->
              <a-popover title="" placement="bottom" trigger="click">
                <template slot="content">
                  <a-table
                    ref="table"
                    size="middle"
                    bordered
                    :scroll="{ x: 500,y: 200}"
                    rowKey="id"
                    :pagination="false"
                    :columns="columnsMedicine"
                    :dataSource="medicineData"
                    :customRow="onSearchRowByMedicine"
                    style="margin-top: 10px" />
                </template>
                <a-auto-complete
                  v-model="medicineValue"
                  :data-source="dataSource"
                  style="width: 95%"
                  placeholder="输入药品名称或拼音码"
                  @search="fetchMedicine"
                  @focus="onSearchFocusByMedicine()"
                >
                  <a-input>
                    <a-icon slot="prefix" type="search" class="certain-category-icon" />
                  </a-input>
                </a-auto-complete>
              </a-popover>
            </a-row>
          </a-card>

          <!--输注处方-->
          <a-card v-if="isInfusion" :headStyle="{color:'#8a8a8a'}">
            <template #title>
              <img src="../../assets/table_icon1.png" /> 输注处方
            </template>
            <a-icon slot="extra" type="save" @click="delMedicine" style="margin-left: 10px" />
            <a-icon slot="extra" type="delete" @click="delMedicine" style="margin-left: 10px" />
            <a-row v-for='(data,parentIndex) in infusionDataSource' style='margin-bottom: 20px' class='bordered-row'>
              <a-row>
                <a-col span='1' align='center' style=';margin-top: 10px'><h2>{{parentIndex+1}}</h2></a-col>
                <a-col span='23'>
                  <a-row style='padding: 10px 0px 10px 0px'>
                    <a-col span='20'>
                      <j-dict-select-tag style="width: 18%"
                                         placeholder="请选择给药途径"
                                         dictCode="infusion_type"
                                         v-model="data.usages" />
                      <j-dict-select-tag style="width: 12%;margin-left: 2%"
                                         placeholder="请选择频率"
                                         dictCode="use_frequency"
                                         v-model="data.frequency" />
                      <a-input-number v-model="data.day"   style="width: 12%;margin-left: 2%" placeholder="天数"  :min="0"  @change="onCallInfusionCalByMinUnit" />
                      <span  style="margin-left: 2px">天</span>
                      <j-dict-select-tag style="width: 16%;margin-left: 2%"
                                         dictCode="infusion_time"
                                         v-model="data.dose" />
                    </a-col>
                    <a-col span='4' align='right'>
                      <a  type="save" @click="delMedicine" style="margin-right: 20px;color: red" >删除</a>
                      <a  type="save"  @click="showTable('输注处方')" style="margin-right: 20px"v-if='infusionDataSource.length==(parentIndex+1)' >加一组</a>
                    </a-col>
                  </a-row>
                  <a-row v-for='(item,childIndex) in data.itemList' style='margin-bottom: 10px'>
                    <a-input-group compact>
                      <a-input v-model='item.medicineName' style='width: 40%'></a-input>
                      <a-select placeholder="请选择确认状态" v-model="item.skin" style='width: 10%'>
                        <a-select-option value="皮试">皮试</a-select-option>
                        <a-select-option value="续用">续用</a-select-option>
                        <a-select-option value="免试">免试</a-select-option>
                      </a-select>
                      <a-input-number v-model="item.dose" placeholder="每次用量" :min="0"  style="width: 8%" @change="onCallInfusionCalByMinUnit" />
                      <a-select v-model='item.conversionUnit'  style="width: 9%" @change="onCallInfusionCalByMinUnit" >
                        <a-select-option v-for='item in item.conversionUnitList' :key='item' :value='item'>{{ item }} </a-select-option>
                      </a-select>
                      <a-input-number  v-model="item.totalDose" style="width: 8%" placeholder="合计"  :min="0"  />
                      <a-select v-model='item.unit'  style="width: 9%" @change="onCallInfusionCalByMinUnit" >
                        <a-select-option v-for='item in item.unitList' :key='item' :value='item'>{{ item }}</a-select-option>
                      </a-select>
                      <a-input v-model='item.remark' placeholder="备注" style='width:14%'></a-input>
                      <a-icon type='delete' @click='delInfusionChild(childIndex)'/>
                    </a-input-group>
                  </a-row>
                </a-col>
              </a-row>
              <a-row style="margin-top: 20px;margin-left: 10px">
                <!--搜索框-->
                <a-popover title="" placement="bottom" trigger="click">
                  <template slot="content">
                    <a-table
                      ref="table"
                      size="middle"
                      bordered
                      :scroll="{ x: 500,y: 200}"
                      rowKey="id"
                      :pagination="false"
                      :columns="columnsMedicine"
                      :dataSource="medicineData"
                      :customRow="onSearchRowByInfusion"
                      style="margin-top: 10px" />
                  </template>
                  <a-auto-complete
                    v-model="infusionValue"
                    style="width: 95%"
                    placeholder="输入药品名称或拼音码"
                    @search="fetchMedicine"
                    @focus="onSearchFocusByInfusion(parentIndex)"
                  >
                    <a-input>
                      <a-icon slot="prefix" type="search" class="certain-category-icon" />
                    </a-input>
                  </a-auto-complete>
                </a-popover>
              </a-row>
              <!--元素底部对齐-->
              <a-row type="flex" justify="center" align="bottom" style="height: 50px;">
                <a-col span="18">
                  <a-input placeholder="备住" auto-size  v-model="data.remark" style="margin-left: 10px;"/>
                </a-col>
                <a-col span="6" align="right"><span style="margin-right: 20px">{{data.itemList.length}} 项&nbsp;&nbsp;&nbsp;合计：￥{{data.totalAmount}}</span></a-col>
              </a-row>
            </a-row>
          </a-card>

          <!--中药处方-->
          <a-card style="margin-top: 20px" v-if="isChineMedicine" :headStyle="{color:'#8a8a8a'}" v-for='(chineMedicine,index) in chineMedicineDataSource'>
            <template #title>
              <img src="../../assets/table_icon2.png" />
              {{chineMedicineDataSource.length<2?"中药处方":"中药处方"+(index+1)}}
            </template>
            <label slot="extra">
            </label>
            <a-select v-model="chineMedicine.attrType" defaultValue="饮片" style="margin-left: 4px;width: 120px" slot="extra">
              <a-select-option value="饮片">饮片</a-select-option>
              <a-select-option value="颗粒">颗粒</a-select-option>
            </a-select>
            <a-checkbox slot="extra" style="margin-left: 10px">
              加工
            </a-checkbox>
            <a-icon slot="extra" type="delete" @click="delChineMedicine" style="margin-left: 10px" />
            <a-row>
              <a-col span="8" v-for="data in chineMedicine.itemList">
                <div class="card">
                  <a-row>
                    <a-col span="21">
                      <label style="font-weight:480;font-size: 18px;color: #8a8a8a">{{ data.medicineName }}</label>
                    </a-col>
                    <a-col span="3">
                      <a-icon type="close" style="color: #dbdbdb" @click="closeChineMedicine(data.medicineId)" />
                    </a-col>
                  </a-row>
                  <a-row style="margin-top: 8px">
                    <a-col span="12">
                      <a-input-number v-model="data.dose" placeholder="用量" style="width:45%;font-size: 15px;color: #8a8a8a" :rows="1" />
                      <a-select v-model='data.conversionUnit'  style="width: 45%;margin-left: 2px">
                        <a-select-option v-for='item in data.conversionUnitList' :key='item' :value='item'>{{ item }} </a-select-option>
                      </a-select>
                    </a-col>
                    <a-col span="12">
                      <j-dict-select-tag
                        style="width: 90%;margin-left: 10px;"
                        placeholder="请选择用法"
                        dictCode="chinese_medicine_use"
                        v-model="model.usages" />
                    </a-col>
                  </a-row>
                </div>
              </a-col>
            </a-row>
            <a-row style="margin-top: 30px" >
              <a-input-number v-model="chineMedicine.doseQty" placeholder="剂量" style="width: 80px;" />
              <label style="margin-left: 6px;font-weight : bold;color: #8a8a8a">剂</label>
              <j-dict-select-tag
                style="width: 150px;margin-left: 6px;"
                placeholder="请选择用法"
                dictCode="drug_delivery_route2"
                v-model="chineMedicine.usages" />
              <!--频次-->
              <j-dict-select-tag
                style="width: 150px;margin-left: 6px;"
                placeholder="请选择服用剂数"
                dictCode="daily_dose"
                v-model="chineMedicine.dailyDose" />

              <j-dict-select-tag
                style="width: 150px;margin-left: 6px;"
                placeholder="请选择服用频次"
                dictCode="use_frequency"
                v-model="chineMedicine.frequency" />

              <j-dict-select-tag
                style="width: 150px;margin-left: 6px;"
                placeholder="每次用量"
                dictCode="dosage_taken"
                v-model="chineMedicine.dose" />
            </a-row>
            <a-row>
              <a-divider />
              <a-col span="20">
                <!--搜索框-->
                <a-popover title="" placement="bottom" trigger="click">
                  <template slot="content">
                    <a-table
                      ref="table"
                      size="middle"
                      bordered
                      :scroll="{ x: 500,y: 200}"
                      rowKey="id"
                      :pagination="false"
                      :columns="columnsMedicine"
                      :dataSource="chineMedicineData"
                      :customRow="onSearchRowByChineMedicine"
                      style="margin-top: 10px" />
                  </template>
                  <a-auto-complete
                    v-model="chineMedicineValue"
                    style="width: 95%"
                    placeholder="输入药品名称或拼音码"
                    @search="fetchChineMedicine"
                    @focus="onSearchFocusByChineMedicine(index)"
                  >
                    <a-input>
                      <a-icon slot="prefix" type="search" class="certain-category-icon" />
                    </a-input>
                  </a-auto-complete>
                </a-popover>
              </a-col>
              <a-col span="3" style="margin-left: 10px;">
                <span style="font-weight: bold;vertical-align: bottom;"> {{chineMedicine.itemList.length}} 项&nbsp;&nbsp;&nbsp;合计：￥{{chineMedicine.totalAmount}}</span>
              </a-col>
            </a-row>
          </a-card>


          <a-card style="margin-top: 20px">
            <a-textarea placeholder="医嘱事项" :rows="2" style="width: 100%" />
          </a-card>
        </div>
      </div>

    </a-col>


    <a-col span="5">
      <a-card :bordered="false">
        <a-row style="width: 100%;height: 850px">
          <a-tabs :defaultActiveKey="activeKey">
            <a-tab-pane key="1" tab="历史">
              <a-collapse v-if="patientHistoryData.length>0" @change="changeActivekey">
                <a-collapse-panel :key="historyData.careCode" :header="historyData.title" v-for="historyData in patientHistoryData">
                  <label slot="extra" type="setting" style="color: #8a8a8a">{{ historyData.doctorName }}</label>
                  <label slot="extra" type="setting"
                         style="margin-left: 10px;color: #8a8a8a">{{ historyData.caseDate }}</label>
                  <h4>病历</h4>
                  <div style="font-weight: 500;color: #8a8a8a">主诉：{{ historyData.caseTitle }}</div>
                  <div style="font-weight: 500;color: #8a8a8a;margin-top: 3px">既往：{{ historyData.historyResult }}</div>
                  <div style="font-weight: 500;color: #8a8a8a;margin-top: 3px">体查：{{ historyData.checkUp }}</div>
                  <div style="font-weight: 500;color: #8a8a8a;margin-top: 3px">过敏：{{ historyData.allergyResult }}</div>
                  <div style="font-weight: 500;color: #8a8a8a;margin-top: 3px">诊断：{{ historyData.caseResult }}</div>

                  <a-row  v-for="(item,index) in historyData.projectDataSource" style="margin-top: 10px">
                    <h4>诊疗项目</h4>
                    <a-row v-for="data in item.itemList">
                      <a-col span="16">{{ data.projectName }}</a-col>
                      <a-col span="8" align="right"><span>{{ date.totalQty}}&nbsp;{{ date.unit }}</span></a-col>
                    </a-row>
                    <a-row style="margin-top: 6px">
                      <a-col span="24" align="right">
                        <span>合计：￥{{item.originalAmount}}</span>
                        <span>实收：￥{{item.amount}}</span>
                      </a-col>
                    </a-row>
                  </a-row>

                  <a-row  v-for="(item,index) in historyData.chineMedicineDataSource" style="margin-top: 10px">
                    <h4 v-if="historyData.chineMedicineDataSource.length>1">中药处方{{index+1}}</h4>
                    <h4 v-if="historyData.chineMedicineDataSource.length==1">中药处方</h4>
                    <a-row v-for="data in item.itemList">
                      <a-col span="16">{{ data.medicineName }}</a-col>
                      <a-col span="8" align="right"><span>{{ date.dose}}&nbsp;{{ date.unit }}</span></a-col>
                    </a-row>
                    <a-row style="margin-top: 6px">
                      <a-col span="24" align="right">
                        <span>合计：￥{{item.originalAmount}}</span>
                        <span>实收：￥{{item.amount}}</span>
                      </a-col>
                    </a-row>
                  </a-row>
                  <a-row  v-for="(item,index) in historyData.medicineDataSource" style="margin-top: 10px">
                    <h4>西药处方</h4>
                    <a-row v-for="data in item.itemList">
                      <a-col span="16">{{ data.medicineName }}</a-col>
                      <a-col span="8" align="right"><span>{{ date.dose}}&nbsp;{{ date.unit }}</span></a-col>
                    </a-row>
                    <a-row style="margin-top: 6px">
                      <a-col span="24" align="right">
                        <span>合计：￥{{item.originalAmount}}</span>
                        <span>实收：￥{{item.amount}}</span>
                      </a-col>
                    </a-row>
                  </a-row>
                  <a-row  v-for="(item,index) in historyData.infusionDataSource" style="margin-top: 10px">
                    <h4 v-if="historyData.infusionDataSource.length>1">输注处方{{index+1}}</h4>
                    <h4 v-if="historyData.infusionDataSource.length==1">输注处方</h4>
                    <a-row v-for="date in item.itemList">
                      <a-col span="16">{{ date.medicineName }}</a-col>
                      <a-col span="8" align="right"><span>{{ date.totalDose}}&nbsp;{{ date.unit }}</span></a-col>
                    </a-row>
                    <a-row style="margin-top: 6px">
                      <a-col span="24" align="right">
                        <span>合计：￥{{item.originalAmount}}</span>
                        <span>实收：￥{{item.amount}}</span>
                      </a-col>
                    </a-row>
                  </a-row>

                  <div>&nbsp;</div>
                </a-collapse-panel>
              </a-collapse>
            </a-tab-pane>
            <a-tab-pane key="2" tab="AI诊断" force-render>
              <a-collapse :defaultActiveKey="caseMainData[0].key" v-if="caseMainData.length>0">
                <a-collapse-panel :key="item.key" :header="item.category" v-for="item in caseMainData"
                                  v-if="item.category.length>0">
                  <a-row>
                    <a-col span="4">
                      <label style="margin-top: 6px;">伴随:</label>
                    </a-col>
                    <a-col span="20">
                      <a-tag v-for="tag in item.itemList" @click="handleChange(tag.name)" style="margin-left: 2px"
                             color="#ffffff">
                        <label style="color: #8a8a8a;font-size: 15px"> {{ tag.name }}</label>
                      </a-tag>
                    </a-col>
                  </a-row>
                  <a-row>
                    <a-col span="4">查体:</a-col>
                    <a-col span="20">
                      <a-tag v-for="tag in item.checkList" @click="handleChange(tag.name)" style="margin-left: 2px"
                             color="#ffffff">
                        <label style="color: #8a8a8a;font-size: 15px"> {{ tag.name }}</label>
                      </a-tag>
                    </a-col>
                  </a-row>
                </a-collapse-panel>
              </a-collapse>
            </a-tab-pane>
          </a-tabs>
        </a-row>
      </a-card>
    </a-col>
    <work-modal ref="workModel"></work-modal>
    <reservation-modal ref="reservationModal"></reservation-modal>
    <cost-browsing-modal ref="costBrowsingModal"></cost-browsing-modal>
    <a-modal v-model="finishVisible" title="完成接诊" @ok="handleOk">
      <div>
        <label style="font-weight: bold;color: #a1a4ad;font-size: 17px">患者:</label>
        <label style="font-weight: bold;font-size: 18px;margin-left: 16px">{{ model.patientName }}</label>
      </div>
      <div style="margin-top: 10px">
        <label style="font-weight: bold;color: #a1a4ad;font-size: 17px;">诊断:</label>
        <label style="font-weight: bold;font-size: 18px;margin-left: 16px">{{ model.caseResult }}</label>
      </div>
      <div style="margin-top: 10px">
        <label style="font-weight: bold;color: #a1a4ad;font-size: 17px;">费用:</label>
        <label style="font-weight: bold;font-size: 18px;margin-left: 16px;color: #efb336">￥10.00</label>
      </div>
    </a-modal>

    <a-modal :maskClosable="false"
             title="病历设置"
             :width="600"
             :visible="setupVisible"
             @cancel="handleCloseSetup"
             @ok="handleOkSetup"
             cancelText="关闭">
      <a-form-model ref="form" :model="careFormatModel">
        <a-form-model-item label="病历格式">
          <a-radio-group v-model="careFormatModel.format">
            <a-radio value="中医">
              中医
            </a-radio>
            <a-radio value="西医">
              西医
            </a-radio>
          </a-radio-group>
        </a-form-model-item>
        <a-form-model-item label="选择需要病历字段">
          <a-checkbox v-model="careFormatModel.careMain.checked" :disabled="careFormatModel.careMain.isSys=='1'">
            {{ careFormatModel.careMain.name }}
          </a-checkbox>
          <a-checkbox v-model="careFormatModel.careDiagnosis.checked"
                      :disabled="careFormatModel.careDiagnosis.isSys=='1'">
            {{ careFormatModel.careDiagnosis.name }}
          </a-checkbox>
          <a-checkbox v-model="careFormatModel.careHistory.checked" :disabled="careFormatModel.careHistory.isSys=='1'">
            {{ careFormatModel.careHistory.name }}
          </a-checkbox>
          <a-checkbox v-model="careFormatModel.careAllergy.checked" :disabled="careFormatModel.careAllergy.isSys=='1'">
            {{ careFormatModel.careAllergy.name }}
          </a-checkbox>
          <a-checkbox v-model="careFormatModel.careCheckUp.checked" :disabled="careFormatModel.careCheckUp.isSys=='1'">
            {{ careFormatModel.careCheckUp.name }}
          </a-checkbox>
          <a-checkbox v-model="careFormatModel.careLook.checked" :disabled="careFormatModel.careLook.isSys=='1'">
            {{ careFormatModel.careLook.name }}
          </a-checkbox>
          <a-checkbox v-model="careFormatModel.careDialectic.checked"
                      :disabled="careFormatModel.careDialectic.isSys=='1'">
            {{ careFormatModel.careDialectic.name }}
          </a-checkbox>
        </a-form-model-item>


      </a-form-model>
    </a-modal>


    <a-modal :maskClosable="false"
             :title="projectTitle"
             :width="1000"
             :visible="projectVisible"
             @cancel="handleCloseSetup"
             @ok="handleOkProject"
             cancelText="关闭">
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="projectDataList"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys,selectionRows:selectionRows,onChange: onSelectChange }">
      </a-table>
    </a-modal>



  </a-row>


</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { deleteAction, getAction, postAction } from '@api/manage'
import moment from 'moment'
import WorkModal from './modules/WorkModal'
import ReservationModal from './modules/ReservationModal'
import CostBrowsingModal from './modules/CostBrowsingModal'

export default {
  name: '门诊',
  mixins: [mixinDevice, JeecgListMixin],
  components: {
    JDictSelectTag,
    WorkModal,
    ReservationModal,
    CostBrowsingModal
  },
  data() {
    return {
      description: '门诊页面',
      disableMixinCreated: true,
      visible: false,
      setupVisible: false,
      finishVisible: false,
      model: {
        attrType: '饮片',
        patientName: ''
      },
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 14 }
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      queryParam: {
        cpType: '0'
      },

      columnsMedicine: [
        {
          title: '药品名称',
          align: 'center',
          dataIndex: 'medicineName',
          width: 200
        },
        {
          title: '规格',
          align: 'center',
          dataIndex: 'standard',
          width: 150
        },
        {
          title: '厂商',
          align: 'center',
          dataIndex: 'factoryName',
          width: 160
        },
        {
          title: '价格',
          align: 'center',
          dataIndex: 'price',
          width: 130
        },
        {
          title: '库存',
          align: 'center',
          dataIndex: 'stock',
          width: 120
        }
      ],
      url: {
        doctorRole: '/store/employee/current/role',
        delete: '/shop/goods',
        batchUp: '/shop/goods/upBatch',
        batchDown: '/shop/goods/downBatch',
        upBatch: '/shop/goods/upBatch',
        regisList: '/his/registration/list',
        medicineSearch: '/his/warehousing/medicine/search',
        aiUrl: '/his/case/ai/list',
        pastHistory: '/his/case/ai/past/history',
        allergyResult: '/his/case/ai/allergyResult',
        diagnosis: '/his/case/ai/diagnosis',
        dialectic: '/his/case/ai/dialectic',
        caseCheckUp: '/his/case/ai/tips',
        submitUrl: '/his/care',
        patientHistory: '/his/care/list',
        getCareFormat: '/his/care/setup/care/format',
        setUpCareFormat: '/his/care/setup/care/format',
        list: '/his/project/list',
        getCareItem: '/his/care/getCareItem'
      },
      dictOptions: {},

      caseMainData: [],//主诉ai智能数据-主诉
      casePastHistoryData: [],//主诉ai智能数据-既往史
      caseAllergyHistoryData: [],//主诉ai智能数据-过敏史
      caseCheckUpData: [],//主诉ai智能数据-体格检查
      caseDiagnosisData: [],//主诉ai智能数据-诊断
      caseDialecticData: [],//主诉ai智能数据-辨证

      todayBegin:"",
      todayEnd:"",
      pageNo: 1,
      loadingMore: false,
      showLoadingMore: true,
      patientData: [],//就诊人员
      patientHistoryData: [ {medicineDataSource:[],chineMedicineDataSource:[],infusionDataSource:[],projectDataSource:[]} ],//就诊人员历史数据
      isChineMedicine: false,//中药 是否显示中药表格
      chineMedicineData: [],//中药  下拉查询数据
      chineMedicineValue: '',//中药
      chineMedicineDataSource: [],//中药  数据表格源
      chineMedicineIndex:0,

      isMedicine: false,//西药 是否显示西药表格
      medicineData: [],//西药  下拉查询数据
      medicineValue: '',//西药
      medicineDataSource: [],//西药  数据表格源
      medicineAmount: 0,//西药  费用


      isInfusion:false,//输注 是否显示输注表格
      infusionData: [],//输注  下拉查询数据
      infusionValue: '',//输注
      infusionDataSource: [],//输注  数据表格源
      infusionAmount: 0,//输注  费用
      infusionIndex:0,
      infusionCalIndex:0,//计算金额索引


      activeKey: '1',
      doctorType: '',//当前医生是中医还是西医
      bodyStyle0: { padding: '0' ,height:'65px',borderRadius: '8px',marginLeft: '2%' },
      bodyStyle1: { padding: '0' ,height:'65px',borderRadius: '8px',marginLeft: '2%',background: '#69c966' },
      chooseId: 0,
      careFormatModel: {
        format: '西医',
        careMain: { isSys: '1', checked: true, name: '主诉' },
        careDiagnosis: { isSys: '1', checked: true, name: '诊断' },
        careHistory: { isSys: '0', checked: false, name: '既往史' },
        careAllergy: { isSys: '0', checked: false, name: '过敏史' },
        careCheckUp: { isSys: '0', checked: false, name: '体格检查' },
        careLook: { isSys: '0', checked: false, name: '望闻问切' },
        careDialectic: { isSys: '0', checked: false, name: '辨证' }
      },
      columns: [
        {
          title: '名称',
          align: 'center',
          dataIndex: 'projectName',
          width: 140
        },
        {
          title: '可用库存',
          align: 'center',
          dataIndex: 'stock',
          width: 100
        },
        {
          title: '价格',
          align: 'center',
          dataIndex: 'saleAmount',
          width: 110,
          customRender: function(t, r, index) {
            return t == 0 ? '~' : '￥' + t
          }
        },
        {
          title: '规格',
          align: 'center',
          dataIndex: 'standard',
          width: 110
        },
        {
          title: '类型',
          align: 'center',
          dataIndex: 'type',
          width: 110
        }, {
          title: '医保',
          align: 'center',
          dataIndex: 'medicalInsuranceCode',
          width: 120
        }
        , {
          title: '医保限制',
          align: 'center',
          dataIndex: 'medicalInsuranceLimit',
          width: 110
        }
      ],
      projectTitle: '',
      projectVisible: false,
      projectDataSource: [],//治疗理疗
      projectDataList: [],
      projectAmount: 0,//输注  费用
      indexByProject:0,


      amountLookTitle: '',
      amountLookVisible: false,
    }
  },
  created() {
    postAction(this.url.doctorRole).then((res) => {
      if (res.success) {
        this.doctorType = res.result
      }
    })
    getAction(this.url.getCareFormat).then((res) => {
      if (res.success) {
        this.careFormatModel = res.result
      }
    })
    this.todayBegin=this.getCurrentDate();
    this.todayEnd=this.getCurrentDate(3);
    this.initialCpCategoryList()
    this.loadPatientData(true)
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    moment,
    getCurrentData() {
      return new Date().toLocaleDateString()
    },
    getCurrentStyle(current, today) {
      const style = {};
      if (current.date() === 1) {
        style.border = '1px solid #1890ff';
        style.borderRadius = '50%';
      }
      return style;
    },
    onChangeByDate(dates, dateStrings) {
      console.log('From: ', dates[0], ', to: ', dates[1]);
      console.log('From: ', dateStrings[0], ', to: ', dateStrings[1]);
      this.todayBegin=dateStrings[0]
      this.todayEnd=dateStrings[1]
      this.loadPatientData(true);
    },
    onLoadMore() {
      this.loadingMore = true
      this.showLoadingMore = false
      this.loadPatientData(false)
    },
    loadPatientData(isRefresh) {
      const that=this;
      if(isRefresh){
         that.pageNo=1;
      }
      getAction(that.url.regisList, {"pageNo":that.pageNo,"beginToday":this.todayBegin,"endToday":this.todayEnd}).then((res) => {
        if (res.success) {
          that.patientData = res.result.records
          if(res.result.totalPages>res.result.pageNo){
            that.showLoadingMore = true;
            that.pageNo++;
          }else{
            that.showLoadingMore = false;
          }
        }
      })
    },
    initialCpCategoryList() {
      let params = {}
      getAction('/shop/category/selectList', params).then((res) => {
        if (res.success) {
          this.cpCategoryList = res.result
        }
      })
    },
    handleChoosePatient(item) {
      if (this.chooseId == item.id) {
        this.chooseId = 0
        this.model.patientId = 0
        this.model.patientName = ''
        this.model.birthday = ''
        return
      }
      this.chooseId = item.id
      this.model.patientId = item.patientId
      this.model.patientName = item.patientName
      this.model.birthday = item.birthday
      this.model.patientSex = item.patientSex
      this.loadPatientHistoryData()
    },
    loadPatientHistoryData() {
      getAction(this.url.patientHistory, { 'patientId': this.model.patientId, 'pageNo': 1 }).then((res) => {
        if (res.success) {
          this.patientHistoryData = res.result.records
        } else {
        }
      }).finally(() => {

      })
    },
    fetchCareMain(text) {
      getAction(this.url.aiUrl, {}).then((res) => {
        if (res.success) {
          this.caseMainData = res.result
          this.activeKey = '2'
        }
      })
    },
    fetchCarePastHistory(text) {
      getAction(this.url.pastHistory, {}).then((res) => {
        if (res.success) {
          this.casePastHistoryData = res.result
        }
      })
    },
    fetchCareAllergyHistory(text) {
      getAction(this.url.allergyResult, {}).then((res) => {
        if (res.success) {
          this.caseAllergyHistoryData = res.result
        }
      })
    },
    fetchCareCheckUpData(text) {
      getAction(this.url.caseCheckUp, {}).then((res) => {
        if (res.success) {
          this.caseCheckUpData = res.result
        }
      })
    },
    fetchCareDiagnosis(text) {
      getAction(this.url.diagnosis, {}).then((res) => {
        if (res.success) {
          this.caseDiagnosisData = res.result
        }
      })
    },
    fetchCaseDialecticData(text) {
      getAction(this.url.dialectic, {}).then((res) => {
        if (res.success) {
          this.caseDialecticData = res.result
        }
      })
    },
    onSearchCareMain() {
    },
    handleChange(value, type) {
      if ('主诉' == type) {
        if (this.model.caseTitle != null && this.model.caseTitle != '' && this.model.caseTitle.length > 0) {
          this.model.caseTitle = this.model.caseTitle + ',' + value
        } else {
          this.model.caseTitle = value
        }
      } else if ('既往史' == type) {
        if (this.model.historyResult != null && this.model.historyResult != '' && this.model.historyResult.length > 0) {
          this.model.historyResult = this.model.historyResult + ',' + value
        } else {
          this.model.historyResult = value
        }
      } else if ('过敏史' == type) {
        if (this.model.allergyResult != null && this.model.allergyResult.length > 0) {
          this.model.allergyResult = this.model.allergyResult + ',' + value
        } else {
          this.model.allergyResult = value
        }
      } else if ('体格检查' == type) {
        if (this.model.checkUp != null && this.model.checkUp.length > 0) {
          this.model.checkUp = this.model.checkUp + ',' + value
        } else {
          this.model.checkUp = value
        }
      } else if ('诊断' == type) {
        if (this.model.caseResult != null && this.model.caseResult.length > 0) {
          this.model.caseResult = this.model.caseResult + ',' + value
        } else {
          this.model.caseResult = value
        }
      } else if ('辨证' == type) {
        if (this.model.dialectic != null && this.model.dialectic.length > 0) {
          this.model.dialectic = this.model.dialectic + ',' + value
        } else {
          this.model.dialectic = value
        }
      }
    },
    showTable(text) {
      if ('中药处方' == text) {
        this.isChineMedicine = true
        this.chineMedicineDataSource.push({
          "attrType":"饮片",
          "doseQty":1,
          "usages":"煎服",
          "dailyDose":"1天1剂",
          "frequency":"1天2次",
          "dose":"每次150ml",
          "totalAmount":"0",
          "itemList":[]
        })
      } else if ('西药处方' == text) {
        this.isMedicine = true
      } else if('输注处方'==text){
        this.isInfusion = true
        this.infusionDataSource.push({
          "usages":"静脉滴注",
          "dailyDose":"1天1剂",
          "frequency":"qd",
          "dose":"15滴/分钟",
          "totalAmount":"0",
          "day":1,
          "itemList":[]
        })
      }
    },
    //诊疗 开始
    handleOpenProject(title, type) {
      this.projectVisible = true
      this.projectTitle = title
      getAction(this.url.list, this.queryParam).then((res) => {
        if (res.success) {
          //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.projectDataList = res.result.records || res.result
          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
          //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
        } else {
          this.$message.warning(res.message)
        }
      }).finally(() => {
        this.loading = false
      })
    },
    handleOkProject: function() {
      const that=this;
      that.selectionRows.forEach(function (d) {
        that.projectDataSource.push({
          'projectName': d.projectName,
          'projectCode': d.projectCode,
          'categoryCode': d.categoryCode,
          'categoryName':d.categoryName,
          'saleAmount':d.saleAmount,
          'unit': d.unit,
          'day': '',
          'qty': '',
          'totalQty':"1",
        })
      });
      that.handleCloseSetup();
    },
    onNumChange(e) {
      const { value } = e.target;
      const reg = /^-?[0-9]*(\.[0-9]*)?$/;
      if ((!isNaN(value) && reg.test(value)) || value === '' || value === '-') {
        this.value = value;
      }
    },
    // '.' at the end or only '-' in the input box.
    onNumBlur() {
      const { value, onChange } = this;
      let valueTemp = value;
      if (value.charAt(value.length - 1) === '.' || value === '-') {
        this.onNumChange({ value: value.slice(0, -1) });
      }
    },
    //诊疗项目计算
    onCallProjectCal(e){
      const index=this.indexByProject;
      if(this.projectDataSource[index].categoryCode=="1"){
        if(this.projectDataSource[index].qty&&this.projectDataSource[index].day){
          let totalQty=this.projectDataSource[index].qty*this.projectDataSource[index].day;
          this.projectDataSource[index].totalQty=totalQty
          this.projectAmount=totalQty*this.projectDataSource[index].saleAmount;
        }
      }
    },
    onFocusProjectCal(index){
      this.indexByProject=index;
    },
    //诊疗 结束

    //中药 开始
    fetchChineMedicine(value) {
      postAction(this.url.medicineSearch, { 'medicineName': value, 'medicineType': '' }).then((res) => {
        if (res.success) {
          this.chineMedicineData = res.result
        }
      })
    },
    onSearchFocusByChineMedicine(index) {
      this.chineMedicineIndex=index;
      if (this.chineMedicineValue == '' || this.chineMedicineValue == undefined) {
        this.fetchChineMedicine('')
      }
    },
    onSearchRowByChineMedicine(record) {
      const that = this
      return {
        on: {
          click: () => {
            let chineMedicine=that.chineMedicineDataSource[that.chineMedicineIndex];
            for (const d in chineMedicine.itemList) {
              if (d['medicineId'] == record.id) {
                return
              }
            }
            that.chineMedicineDataSource[that.chineMedicineIndex].totalAmount=record.price;
            that.chineMedicineDataSource[that.chineMedicineIndex].itemList.push({
              'seq': 1,
              'medicineId': record.id,
              'medicineName': record.medicineName,
              'conversionUnit': record.conversionUnit==""?record.unit:record.conversionUnit,
              'unit': record.unit,
              'unitList':record.unitList,
              'dose': '1',
              'price':record.price,
              'salePrice':record.salePrice,
              'cost':record.price,
            })
          }
        }
      }
    },
    delChineMedicine() {
      this.chineMedicineDataSource = []
      this.isChineMedicine = false
    },
    closeChineMedicine(mId) {
      let newArr = this.chineMedicineDataSource.filter(item => item.medicineId !== mId)
      this.chineMedicineDataSource = newArr
    },
    //中药 结束

    //西药 开始
    fetchMedicine(value) {
      postAction(this.url.medicineSearch, { 'medicineName': value, 'medicineType': 'WESTERN_MEDICINE' }).then((res) => {
        if (res.success) {
          this.medicineData = res.result
        }
      })
    },
    onSearchFocusByMedicine() {
      if (this.medicineValue == '' || this.medicineValue == undefined) {
        this.fetchMedicine('')
      }
    },

    onSearchRowByMedicine(record) {
      const that = this
      return {
        on: {
          click: () => {
            for (const d in that.medicineDataSource) {
              if (d['medicineId'] == record.id) {
                return
              }
            }
            let day=1;
            that.medicineAmount+=record.price*day;
            that.medicineDataSource.push({
              'seq': 1,
              'medicineId': record.id,
              'medicineName': record.medicineName,
              'unit': record.unit,
              'conversionUnit': record.conversionUnit,
              'conversion': record.conversion,
              'oldUnit': record.oldUnit,
              'standard': record.standard,
              'unitList':record.unitList,
              'conversionUnitList':record.conversionUnitList,
              'usages': '口服',
              'frequency': 'tid',
              'totalDose': '1',
              'dose': '1',
              'day':day,
              'price':record.price,
              'salePrice':record.salePrice,
              'cost':record.price,
              'izSplitSale':record.izSplitSale,
            })
          }
        }
      }
    },

    delMedicine() {
      this.medicineDataSource = []
      this.isMedicine = false
    },
    onCallWesternCalByMinUnit(e){
      const that=this;
      that.medicineAmount=0;
      that.medicineDataSource.forEach(function(p,pIndex){
        if(p.day==undefined||p.day==''){
           p.day=1;
        }
        //包装单位不变 计算金额
        if (p.oldUnit==p.unit&&p.unit!=p.conversionUnit){
            let totalDose=Math.ceil((p.dose*p.day)/p.conversion);
            p.totalDose=totalDose;
            p.cost = p.price;
        }else if(p.oldUnit!=p.unit&&p.unit==p.conversionUnit){
            p.totalDose=p.dose*p.day;
            p.cost = p.salePrice;
        }else if(p.oldUnit==p.unit&&p.unit==p.conversionUnit){
            p.totalDose=p.dose*p.day;
            p.cost = p.price;
        }
        that.medicineAmount+=  p.totalDose*p.cost;
      });
    },
    //西药项目计算
    onCallWesternCalByMaxUnit(e){
      const that=this;
      that.medicineAmount=0;
      that.medicineDataSource.forEach(function(p,pIndex){
        //包装单位不变 计算金额
        if (p.oldUnit==p.unit){
             p.cost = p.price;
             that.medicineAmount+=  p.totalDose*p.cost;
        }else if(p.unit!=p.oldUnit){//包装单位不一样
             p.cost = p.salePrice;
             that.medicineAmount+=  p.totalDose*p.cost;
        }
        that.medicineAmount=parseFloat( that.medicineAmount).toFixed(2);
      });
    },

    //西药 结束

    //输注 开始
    onSearchFocusByInfusion(index) {
      this.infusionIndex=index;
      if (this.infusionValue == '' || this.infusionValue == undefined) {
        this.fetchMedicine('')
      }
    },
    onSearchRowByInfusion(record) {
      const that = this
      return {
        on: {
          click: () => {
            let chineMedicine=that.infusionDataSource[that.infusionIndex];
            for (const d in chineMedicine.itemList) {
              if (d['medicineId'] == record.id) {
                return
              }
            }
            that.infusionDataSource[that.infusionIndex].totalAmount=record.price
            that.infusionDataSource[that.infusionIndex].itemList.push({
              'seq': 1,
              'medicineId': record.id,
              'medicineName': record.medicineName,
              'unit': record.unit,
              'conversionUnit': record.conversionUnit,
              'conversion': record.conversion,
              'oldUnit': record.oldUnit,
              'standard': record.standard,
              'unitList':record.unitList,
              'conversionUnitList':record.conversionUnitList,
              'skin':"免试",
              'totalDose': '1',
              'dose': '1',
              'price':record.price,
              'salePrice':record.salePrice,
              'cost':record.price,
              'izSplitSale':record.izSplitSale,
            })
          }
        }
      }
    },

    delInfusionChild(index){
      this.infusionDataSource[this.infusionIndex].itemList.splice(index,1);
    },

    onCallInfusionCalByMinUnit(e){
      const that=this;

      that.infusionDataSource.forEach(function(d,pIndex){
         if(d.day==undefined||d.day==""){
            d.day=1
         }
          d.itemList.forEach(function(p,index){
          //包装单位不变 计算金额
          if (p.oldUnit==p.unit&&p.unit!=p.conversionUnit){
            let totalDose=Math.ceil((p.dose*d.day)/p.conversion);
            p.totalDose=totalDose;
            p.cost = p.price;
          }else if(p.oldUnit!=p.unit&&p.unit==p.conversionUnit){
            p.totalDose=p.dose*d.day;
            p.cost = p.salePrice;
          }else if(p.oldUnit==p.unit&&p.unit==p.conversionUnit){
            p.totalDose=p.dose*d.day;
            p.cost = p.price;
          }
          d.totalAmount=p.totalDose*p.cost;
        });
      });
    },
    //西药项目计算
    onCallInfusionCalByMaxUnit(e){
      const that=this;
      that.medicineAmount=0;
      that.medicineDataSource.forEach(function(p,pIndex){
        //包装单位不变 计算金额
        if (p.oldUnit==p.unit){
          p.cost = p.price;
          that.medicineAmount+=  p.totalDose*p.cost;
        }else if(p.unit!=p.oldUnit){//包装单位不一样
          p.cost = p.salePrice;
          that.medicineAmount+=  p.totalDose*p.cost;
        }
        that.medicineAmount=parseFloat( that.medicineAmount).toFixed(2);
      });
    },

    //输注 结束

    initDictConfig() {
    },
    handleOk() {
      const that = this
      this.model.medicineDataSource = this.medicineDataSource
      this.model.chineMedicineDataSource = this.chineMedicineDataSource
      this.model.projectDataSource=this.projectDataSource
      this.model.infusionDataSource=this.infusionDataSource
      postAction(this.url.submitUrl, this.model).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          that.finish()
          that.finishVisible = false
        } else {
          that.$message.warning(res.message)
        }
      }).finally(() => {
        that.loading = false
      })
    },
    handleSubmit: function(submitType) {
      if (this.model.patientId == 0 || this.model.patientId == null) {
        this.$message.warning('请选择患者就诊')
        return
      }
      if (this.model.caseResult == '' || this.model.caseResult == null) {
        this.$message.warning('请为患者确定诊断信息')
        return
      }
      this.finishVisible = true
      this.model.submitType = submitType
    },
    finish() {
      this.model.patientName = ''
      this.model.id = ''
      this.model.birthday = ''
      this.model.medicineDataSource = []
      this.model.chineMedicineDataSource = []
      this.chineMedicineDataSource = []
      this.medicineDataSource = []
      this.isMedicine = false
      this.isChineMedicine = false
    },
    handleOpenWork: function() {
      this.$refs.workModel.show()
      this.$refs.workModel.title = '工作汇总'
      this.$refs.workModel.disableSubmit = false
    },
    handleOpenReservation: function() {
      this.$refs.reservationModal.show()
      this.$refs.reservationModal.title = '预约情况'
      this.$refs.reservationModal.disableSubmit = false
    },
    handleOpenCostBrowsing: function() {
      this.model.medicineDataSource = this.medicineDataSource
      this.model.chineMedicineDataSource = this.chineMedicineDataSource
      this.model.projectDataSource=this.projectDataSource
      this.model.infusionDataSource=this.infusionDataSource
      this.model.medicineAmount=this.medicineAmount;
      this.$refs.costBrowsingModal.show(this.model)
      this.$refs.costBrowsingModal.title = '费用预览'
      this.$refs.costBrowsingModal.disableSubmit = false
    },
    handleSetUp: function() {
      this.setupVisible = true
    },
    handleCloseSetup: function() {
      this.setupVisible = false
      this.projectVisible = false
      this.amountLookVisible=false;
    },
    handleOkSetup: function() {
      const that = this
      postAction(this.url.setUpCareFormat, this.careFormatModel).then((res) => {
        if (res.success) {
          that.$message.success(res.message)
          this.setupVisible = false
        } else {
          that.$message.warning(res.message)
        }
      }).finally(() => {
        that.loading = false
      })
    },
    changeActivekey(key) {
      const that=this;
      const careCode=key[0];
      getAction(this.url.getCareItem,{"careCode":careCode}).then((res) => {
        if (res.success) {
          const result=res.result;
          that.patientHistoryData.forEach(function (d,index) {
             if(d.careCode==careCode){
               that.patientHistoryData[index].medicineDataSource=result.medicineDataSource;
               that.patientHistoryData[index].infusionDataSource=result.infusionDataSource;
               that.patientHistoryData[index].projectDataSource=result.projectDataSource;
             }
          });
        }
      })
    },



  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

#example-table-id {
  text-align: center;
  white-space: pre-line;
  word-wrap: break-word;
  word-break: break-all
}

/* 取消 多行文本框 伸缩效果 resize: none; */
/* 取消 多行文本框 边框 border: none; */
textarea.ant-input {
  resize: none;
  border: none;
}

/* 取消 多行文本框 获取焦点的 边框 效果 */
textarea.ant-input:focus {
  border: none;
  box-shadow: none;
}

table {
  width: 100%;
  border-collapse: collapse; /* 合并表格边框 */
}

th, td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

th {
  background-color: #f2f2f2;
}

tr:nth-child(even) {
  background-color: #f9f9f9;
}

tr:hover {
  background-color: #e2e2e2;
}

.card {
  border: 1px solid #f6f5f5;
  border-radius: 5px;
  padding: 4px 2px 20px 10px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin-right: 20px;
}
.bordered-row {
  border: 1px solid #d9d9d9; /* 边框样式，你可以根据需要自定义颜色和宽度 */
  border-radius: 4px; /* 可选：为行添加圆角 */
  padding-bottom: 10px;
}

.active  {
  background: linear-gradient(to right, #69c966, #20757c);
  height: 40px;
  cursor: pointer;
}

.patient-item{
  position: relative;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  height: 40px;
  padding: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  background: #fff;
  border-radius: 4px;
}

.transition-input-box-panel__body{
  position: absolute;
  z-index: 999;

}
</style>
